<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>-->
    <!--<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>-->
    <!--<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>-->
    <!--[endif]-->
    <script type="text/javascript" src="../../common/js/public.js"></script>
    <script type="text/javascript" src="../../common/js/publicUtils.js"></script>

</head>
<body>
<div class="layui-fluid" id="flowDiv">
    <div class="zTreeBackground right layui-form" style="padding-left:1%;width:98%">
        <div class="layui-form-item" style="width:99%;margin-bottom:-10px;text-align:right;">
            <div class="layui-inline">
                <label class="layui-form-label">所属岗位</label>
                <div class="layui-input-block">
                    <select name="job" id="job" lay-filter="job">
                    </select>
                    <!--<i class="layui-icon layui-icon-search" style="position: absolute;top:8px;right: 8px;" onclick="easysearch()"></i>-->
                </div>
            </div>
            <!--<button type="button" style="margin-left:12px;margin-top: -12px;" class="layui-btn layui-btn-normal" onclick="moresearch()"><i class="layui-icon layui-icon-search"></i>高级搜索</button>-->
        </div>
        <!--<div class="search_float_div" style="position:absolute;z-index:999;width:99%;background-color: #f1f1f1;padding-top: 20px;text-align:left;display:none">-->
            <!--<div class="layui-form-item">-->
                <!--<div class="layui-inline" style="width:400px;">-->
                    <!--<label class="layui-form-label">名称</label>-->
                    <!--<div class="layui-input-inline">-->
                        <!--<input type="text" id="name" autocomplete="off" class="layui-input">-->
                    <!--</div>-->
                <!--</div>-->
                <!--<div class="layui-inline" style="width:400px;">-->
                    <!--<label class="layui-form-label">组织类型</label>-->
                    <!--<div class="layui-input-inline">-->
                        <!--<input type="text" id="orgType" autocomplete="off" class="layui-input">-->
                    <!--</div>-->
                <!--</div>-->
            <!--</div>-->
            <!--<div class="layui-form-item">-->
                <!--<div class="layui-input-block">-->
                    <!--<button type="button" style="float: left;margin-left: 12px" class="layui-btn layui-btn-normal" onclick="searchTable()"><i class="layui-icon layui-icon-search"></i>查询</button>-->
                    <!--<button type="button" class="layui-btn layui-btn-primary" onclick="canclesearch()">取消</button>-->
                <!--</div>-->
            <!--</div>-->
        <!--</div>-->
        <table class="layui-hide" id="datatable" lay-filter="datatable"></table>
        <script type="text/html" id="toolbar"></script>

    </div>

</div>
</body>
<SCRIPT type="text/javascript">
    var zTreeObj,jobid,form,tableObj,table,level=0,treeNodeId=-1,selecNode,count=1,hideflag=true;
    $(function(){
        loadbutton("toolbar");//加载按钮loadbutton(id)，id为button容器id，不传默认为buttongroup
        initJobSelect();
        loadTable();
    })

    //初始化所属岗位下拉框
    function initJobSelect(){
        layui.use('form',function(){
            var form = layui.form;
            publicAjax(null,'infdictitem/selectInfdictitemByInfdictsortCode',{'code':'OrgJob'},false,null,function (data){
                if(data.code == 2000){
                    var selectStr = '<option value="0">请选择所属岗位</option>';
                    var jobs= data.data;
                    for(var i=0;i<jobs.length;i++){
                        selectStr = selectStr + "<option value='"+jobs[i].code+"'>"+jobs[i].name+"</option>";
                    }
                    $("#job").html('');
                    $("#job").html(selectStr);
                    form.render();
                }
            });
            form.on('select(job)', function(data){
                loadTable(data.value); //
            });
        })

    }
    /* *
     * @Author bxf
     * @Description 高级搜索
     * @Date 17:34 2019/8/30
     * @param null
     * @return
     */
    function moresearch(){
        $(".search_float_div").slideToggle();
    }
    /* *
     * @Author bxf
     * @Description 简单查询
     * @Date 17:46 2019/8/30
     * @param null
     * @return
     */
    function easysearch(){
        var job = $("#job").val();
        loadTable(job);
    }
    /* *
     * @Author bxf
     * @Description 取消查询
     * @Date 17:44 2019/8/30
     * @param null
     * @return
     */
    function canclesearch(){
        $("#job").val('');
        $(".search_float_div").slideToggle();//关闭搜素div
    }
    /* *
     * @Author bxf
     * @Description 搜索table数据
     * @Date 17:51 2019/8/30
     * @param null
     * @return
     */
    function searchTable(){
        var job = $("#job").val();
        loadTable(job);
        $(".search_float_div").slideToggle();//关闭搜素div
    }
    /* *
     * @Author bxf
     * @Description 初始化table
     * @Date 17:51 2019/8/30
     * @param null
     * @return
     */
    function loadTable(job){
            var cols = [
                [  {type:'checkbox'},{
                    title: '序号',
                    type: 'numbers',
					width: "3%",
                    align: 'center'
                }, {
                    field: 'code',
                    title: '编号',
					width: "16%",
                    sort: true,
                    align: 'center'
                }, {
                    field: 'name',
                    title: '职责内容',
					width: "20%",
                    sort: true,
                    align: 'center'
                },  {
                    field: 'jobName',
                    title: '所属岗位',
					width: "14%",
                    sort: true,
                    align: 'center'
                }, {
                    field: 'description',
                    title: '职责内容',
					width: "42%",
                    sort: true,
                    align: 'left'
                }]
            ];
            layui.use('table', function() {
                table = layui.table;
                table.render({
                    elem: '#datatable',
                    size: 'sm',
                    even: true, //开启隔行背景
                    toolbar: '#toolbar',
                    height: 'full-100',
                    url:publicUrl+'job/getJobs',
                    //data: data,
                    method: 'post',
                    headers: {"Authorization":getData("Authorization")},
                    cols: cols,
                    where :{
                      'job':job
                    },
                    parseData: function(res){ //res 即为原始返回的数据
                        return formatTableParseData(res);
                    },
                    response: {
                        statusCode: 2000,
                    },
                    limit: 20,
                    page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                        layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'] //自定义分页布局
                    }
                });
            })
    }

    function uploadjob(){
        var iframeWin ;
        layer.open({
            type: 2,
            area: ["500px" , "350px"],
            fix: false,
            //不固定
            maxmin: false,
            shade: 0.3,
            title: "导入岗位职责",
            content: "./uploadjob.html",
            btn: ['关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            yes: false,
            cancel: function(index) {
                return true;
            },
            success: function(layero, index){
                iframeWin = layero.find('iframe')[0];
            }
        });
    }
    /**
     * @Author bxf
     * @Description 添加工艺工法
     * @Date 9:51 2019/7/18
     * @Param
     * @return
     **/
    function addjob(){
        var iframeWin ;
        layer.open({
            type: 2,
            area: ["640px" , "450px"],
            fix: false,
            //不固定
            maxmin: false,
            shade: 0.3,
            title: "新增岗位职责",
            content: "./addjob.html",
            btn: ['应用','确定', '关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            yes: function(index, layero) {
                var resultdata = iframeWin.contentWindow.submitData();//应用
                if(resultdata && resultdata.code==2000){
                    loadTable();
                }
                return false;
                //layer.closeAll();
            },
            btn2: function(index, layero){
                //按钮【按钮二】的回调
                var resultdata = iframeWin.contentWindow.submitData();//保存
                if(resultdata && resultdata.code==2000){
                    loadTable();
                    layer.closeAll();
                }else{
                    return false;
                }
            },
            btn3: function(index, layero){

                },
            cancel: function(index) {
                return true;
            },
            success: function(layero, index){
                iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.voluate(1);//添加按钮
            }
        });
    }

    /**
     * @Author bxf
     * @Description 修改工艺工法页面
     * @Date 9:51 2019/7/18
     * @Param
     * @return
     **/
    function updatejob(){
        var obj = table.checkStatus('datatable');
        if(!obj || obj.data.length!=1){
            layer.alert("请选择一项信息进行修改！");
            return false;
        }
        var data = obj.data[0]; //idTest 即为基础参数 id 对应的值
        var iframeWin ;
        layer.open({
            type: 2,
            area: ["640px" , "450px"],
            fix: false,
            //不固定
            maxmin: false,
            shade: 0.3,
            title: "编辑岗位职责",
            content: "./addjob.html",
            btn: ['确定', '关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            yes: function(index, layero) {
                var resultdata = iframeWin.contentWindow.updateData();
                if(resultdata && resultdata.code==2000){
                    loadTable();
                    delayLoad(function(){
                        layer.closeAll();
                    },1000)
                }else {
                    return false;
                }
            },
            cancel: function(index) {
                return true;
            },
            success: function(layero, index){
                iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.voluate(2,data);//添加按钮
            }
        });
    }
    //删除按钮初始化
    function deleteData(){
            var idStr = "";
            //获取表格选中
            var selectData = layui.table.checkStatus('datatable').data;
            if(typeof(selectData)!="undefined" && selectData!=null && selectData.length>0){
                layer.confirm('确认删除吗？', {
                    btn: ['确定','取消'] //按钮
                }, function(index){
                    for(var i=0;i<selectData.length;i++){
                        idStr = idStr + selectData[i].id + ",";
                    }
                    publicAjax(null,'job/delete',{"idStr":idStr},false,null,function(r){
                        if(r.code==2000){
                            laysuccess("删除成功！");
                        }else{
                            layerror("删除失败！");
                        }
                        loadTable();
                    })
                }, function(){

                });
            }
    }


</script>
</html>